const connections = require('../app/database');

class LabelService {
    async create(name) {
        const statement = `
            INSERT INTO label (name) VALUES (?);
        `;
        const [result] = await connections.execute(statement, [name]);
        return result;
    }

    async select(name) {
        const statement = `
            SELECT name AS labelName 
            FROM label
            WHERE name = ?;
        `;
        const [result] = await connections.execute(statement, [name]);
        return result;
    }

    async getLabelName(name) {
        const statement = `
            SELECT * FROM label WHERE name = ?;
        `;
        const [result] = await connections.execute(statement, [name]);
        return result[0];
    }

    async getLabels(limit, offset) {
        const statement = `
            SELECT * FROM label LIMIT ?, ?;
        `;
        const [result] = await connections.execute(statement, [limit, offset]);
        return result;
    }
}

module.exports = new LabelService();